import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JMenuBar;

public class ShapeMenuBar extends JMenuBar {
	private static final long serialVersionUID = 5241343565481095793L;

	public ShapeMenuBar(final ObjectAttacher rootAttacher) {
		if (rootAttacher == null)
			throw new IllegalArgumentException();
		generateButtons(rootAttacher);
	}
	
	private void generateButtons(final ObjectAttacher rootAttacher) {
		JButton circle = new JButton("Add Circle");
		circle.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Circle c = new Circle(1f);
				c.acceleration.y = PhysicsObject.GRAVITY;
				rootAttacher.attachObject(c);
			}
		});
		add(circle);
		
		JButton demo = new JButton("Add Demo");
		demo.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Triangle a = new EqualatTriangle(1);
				a.position.x = .5001f;
				a.position.y = -3f;
				a.acceleration.y = PhysicsObject.GRAVITY;
				Triangle b = new EqualatTriangle(1);
				b.position.x = -.5001f;
				b.position.y = -3f;
				b.acceleration.y = PhysicsObject.GRAVITY;
				Triangle c = new Triangle(1);
				c.position.x = -0.32f;
				c.orientation = -(float) Math.PI * 0.75f;
				c.acceleration.y = PhysicsObject.GRAVITY;
				Circle d = new Circle(1f);
				d.acceleration.y = PhysicsObject.GRAVITY * 0.5f;
				d.position.y = 3.8f;
				rootAttacher.attachObject(a);
				rootAttacher.attachObject(b);
				rootAttacher.attachObject(c);
				rootAttacher.attachObject(d);
			}
		});
		add(demo);

//		JButton triforce = new JButton("Add Triforce");
//		triforce.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				sceneGraphRoot.addChild(new Triforce());
//			}
//		});
//		add(triforce);
		
		JButton square = new JButton("Add Square");
		square.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Square s = new Square(1f, true);
				s.acceleration.y = PhysicsObject.GRAVITY;
				s.orientation = (float) Math.PI * 1.25f;
				rootAttacher.attachObject(s);
			}
		});
		add(square);
		
		/*
		 * JButton star = new JButton("Add Star"); star.addActionListener(new
		 * ActionListener() {
		 * 
		 * @Override public void actionPerformed(ActionEvent arg0) {
		 * sceneGraphRoot.addChild(new Star()); } }); add(star);
		 */
		
		JButton rectangle = new JButton("Add Rectangle");
		rectangle.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Rectangle rt = new Rectangle(2f, 1f);
				rt.acceleration.y = PhysicsObject.GRAVITY;
				rootAttacher.attachObject(rt);
			}
		});
		add(rectangle);

		JButton eqtri = new JButton("Add Equalateral Triangle");
		eqtri.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				EqualatTriangle eqt = new EqualatTriangle(1f);
				eqt.acceleration.y = PhysicsObject.GRAVITY;
				eqt.velocity.x = 1f;
				eqt.velocity.y = 1f;
				rootAttacher.attachObject(eqt);
			}
		});
		add(eqtri);

		JButton sun = new JButton("Add Sun");
		sun.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Sun sunobj = new Sun(1f, true);
				sunobj.acceleration.y = PhysicsObject.GRAVITY;
				rootAttacher.attachObject(sunobj);
			}
		});
		add(sun);

		JButton right_triangle = new JButton("Add Right Triangle");
		right_triangle.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Triangle t = new Triangle(1f);
				t.acceleration.y = PhysicsObject.GRAVITY;
				rootAttacher.attachObject(t);
			}
		});
		add(right_triangle);

//		JButton sierpinski = new JButton("Add Sierpinski");
//		sierpinski.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				sceneGraphRoot.addChild(new SierpinskiTriangle(5));
//			}
//		});
//		add(sierpinski);
	}
}
